import * as actionType from "./actionType"
import { ManagementList, SpecificQuery,GradeSortList,MoneySortList,OrderSortList,TimeSortList} from "../../http/customerApi"

export const getIdAction = (id) => ({
  type: actionType.GET_Id,
  id,
})
export const getUserAction = (obj) => ({
  type: actionType.GET_USER,
  obj,
})
export const setPage = (current, pageSize) => ({
  type: actionType.SET_PAGE,
  current,
  pageSize
})
// export const logoutAction = () => ({
//   type: actionType.USER_LOGOUT,
// })

export const getManagementList = (list, count) => {
  console.log('zzzz', actionType.GET_ManagementList);
  return ({
    type: actionType.GET_ManagementList,
    list,
    count
  })
}




// 获取管理列表异步
export const ManagementAsync = (data) => (dispatch) =>
  ManagementList(data.currentPage, data.pageSize)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })

// 获取订单排序列表异步
export const OrderSortListAsync = (data) => (dispatch) =>
OrderSortList(data.currentPage, data.pageSize)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })

// 获取贷款金额排序列表异步
export const MoneySortListAsync = (data) => (dispatch) =>
MoneySortList(data.currentPage, data.pageSize)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })
// 获取会员排序列表异步
export const GradeSortListAsync = (data) => (dispatch) =>
  GradeSortList(data.currentPage, data.pageSize)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })

// 获取注册排序列表异步
export const TimeSortListAsync = (data) => (dispatch) =>
TimeSortList(data.currentPage, data.pageSize)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })

// 搜索异步
export const SpecificQueryAsync = (data) => (dispatch) =>
  SpecificQuery(data.currentPage, data.pageSize, data.userObj)
    .then((res) => {
      console.log('action', res.data);
      console.log(actionType);
      if (res.data.code === 200) {
        dispatch(
          getManagementList([
            ...res.data.data
          ], res.data.count)
        )
        return Promise.resolve("success")
      } else {
        return Promise.reject(res.data)
      }
    })
    .catch((err) => {
      console.log('action失败');
      return Promise.reject(err)
    })